package us.icitap.cm.ui.policecase;

import us.icitap.cm.business.entities.AppEntity;
import us.icitap.cm.business.entities.EntityTypeEnum;

import com.vaadin.ui.Tree;

public class CaseTree extends Tree {

	public CaseTree() {
		
		this.addItem("CASE");
		this.setItemCaption("CASE", "Ceshtje nr.-----");
		
//		this.addItem(EntityTypeEnum.ER);
//		this.setItemCaption(EntityTypeEnum.ER, EntityTypeEnum.ER.getCaption());
//		System.out.println(CaseManagementUI.getActualAction());
//		if(ActionEnum.NEW_SR.equals(CaseManagementUI.getActualAction())){
//			this.addItem(EntityTypeEnum.SR);
//			this.setItemCaption(EntityTypeEnum.SR, EntityTypeEnum.SR.getCaption());
//			this.setParent(EntityTypeEnum.SR, "CASE");
//		}
//		
		
		this.addItem(EntityTypeEnum.PLACE);
		this.setItemCaption(EntityTypeEnum.PLACE, EntityTypeEnum.PLACE.getCaption());
		
		this.addItem(EntityTypeEnum.PERSON);
		this.setItemCaption(EntityTypeEnum.PERSON, EntityTypeEnum.PERSON.getCaption());
		
		this.addItem(EntityTypeEnum.DOCUMENT);
		this.setItemCaption(EntityTypeEnum.DOCUMENT, EntityTypeEnum.DOCUMENT.getCaption());
		
		this.addItem(EntityTypeEnum.VEHICLE);
		this.setItemCaption(EntityTypeEnum.VEHICLE, EntityTypeEnum.VEHICLE.getCaption());

		this.addItem(EntityTypeEnum.ITEM);
		this.setItemCaption(EntityTypeEnum.ITEM, EntityTypeEnum.ITEM.getCaption());
		
		this.addItem(EntityTypeEnum.DRUG);
		this.setItemCaption(EntityTypeEnum.DRUG, EntityTypeEnum.DRUG.getCaption());
		
		this.addItem(EntityTypeEnum.WEAPON);
		this.setItemCaption(EntityTypeEnum.WEAPON, EntityTypeEnum.WEAPON.getCaption());
		
		this.addItem(EntityTypeEnum.ORGANIZATION);
		this.setItemCaption(EntityTypeEnum.ORGANIZATION, EntityTypeEnum.ORGANIZATION.getCaption());
		
		this.addItem(EntityTypeEnum.OFFICER);
		this.setItemCaption(EntityTypeEnum.OFFICER, EntityTypeEnum.OFFICER.getCaption());
		
		this.addItem("ASSOCIATIONS");
		this.setItemCaption("ASSOCIATIONS", "Lidhjet");
		
//		this.setParent(EntityTypeEnum.ER, "CASE");
		
		this.setParent(EntityTypeEnum.PLACE, "CASE");
		this.setParent(EntityTypeEnum.PERSON, "CASE");
		this.setParent(EntityTypeEnum.DOCUMENT, "CASE");
		this.setParent(EntityTypeEnum.VEHICLE, "CASE");
		this.setParent(EntityTypeEnum.DRUG, "CASE");
		this.setParent(EntityTypeEnum.WEAPON, "CASE");
		this.setParent(EntityTypeEnum.ITEM, "CASE");
		this.setParent(EntityTypeEnum.NUMBER, "CASE");
		this.setParent(EntityTypeEnum.ORGANIZATION, "CASE");
		this.setParent(EntityTypeEnum.OFFICER, "CASE");
		this.setParent("ASSOCIATIONS", "CASE");
		
		this.expandItemsRecursively("CASE");
		this.setImmediate(true);
		this.setItemStyleGenerator(new ItemStyleGenerator() {
		    
			@Override
			public String getStyle(Tree source, Object itemId) {
				if(itemId instanceof AppEntity && itemId != null ){
					AppEntity appEntity = (AppEntity) itemId;
					System.out.println(appEntity.toString() + "-->" + appEntity.isNewRecord());
					if(!appEntity.isNewRecord()) return "treeItemBlue";
					else return "treeItemYellow";
				}
				return null;
			}
		});
		
		
	}
	
	
}
